import requests
class Actor:
    def __init__(self):
        self.session = requests.Session()
        headers = {"Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImZmZmMwMjZkLTA0ZDgtNDc0MC04NmIyLTk3OGFiZjNlNTQwZiJ9.WHm2QsidoAetsNuRmWW6z9kH4cGWFuXAFqkzKOgCkhvTRVjLol_a3b0EbK9MgymRvc01V8bWD7bc1vzh7Rkghw"}
        self.session.headers.update(headers)

    # 根据ID查询 演员信息 返回值  接口返回什么 此函数的返回值 取它的JSON数据
    def search_actor_id(self,id):
        url = "http://api.51tickets.com/system/actor/list?pageNum=1&pageSize=10"
        params = {
            "pageNum": 1,
            "pageSize": 10,
            # "actorName":"亚鹿"
            "actorId": id
        }
        resp = self.session.get(url=url, headers=headers, params=params)
        print(resp.json())
        return resp.json()

    # 根据演员的姓名查询演员信息
    def search_actor_name(self,actorName):
        url = "http://api.51tickets.com/system/actor/list?pageNum=1&pageSize=10"
        params = {
            "pageNum": 1,
            "pageSize": 10,
            "actorName": actorName
        }
        resp = self.session.get(url=url, params=params)
        print(resp.json())
        return resp.json()

    # 上传文件
    def upload_image(self,path):
        pass

    # 保存演员
    def add_actor(self,actorName,description):
        url = "http://api.51tickets.com/system/actor"
        body = {
            "actorId": None,
            "actorName": actorName,
            "actorImg":None,
            "actorDesc": description,
            "followers": None,
            "boxOffice": None
        }
        resp = self.session.post(url=url, json=body)
        print(resp.json())
        return resp.json()

    #更新演员信息
    def modify_actor(self,actorId,actorName,description):
        url = "http://api.51tickets.com/system/actor"
        body = {
            "searchValue": None,
            "createBy": None,
            "createTime": None,
            "updateBy": None,
            "updateTime": None,
            "remark": None,
            "params": {},
            "actorId": actorId,
            "actorName": actorName,
            "actorImg": None,
            "actorDesc": description,
            "followers": 0,
            "boxOffice": 0
        }
        resp = self.session.put(url=url, json=body)
        print(resp.json())
        return resp.json()

    # 删除演员信息
    def remove_actor(self,actorId):
        url = f"http://api.51tickets.com/system/actor/{actorId}"
        resp = self.session.delete(url=url)
        print(resp.json())
        return resp.json()

if __name__ == '__main__':
    actor = Actor()
    # actor.search_actor_id(147)
    # actor.search_actor_name("雷佳音")
    # actor.add_actor("小四","发财")
    # actor.modify_actor("270","xiaowu","good")
    # actor.remove_actor("271")